package com.winchain.chainbill.basic.activity.controller;

import com.shell.bee.base.annotation.Logging;
import com.shell.bee.base.utils.StringUtil;
import com.shell.bee.mvc.controller.BaseController;
import com.shell.bee.persistence.model.PageLimit;
import com.shell.framework.utils.CommonDataUtil;
import com.shell.framework.utils.CommonFileUtil;
import com.winchain.chainbill.basic.activity.service.BasCusCpnService;
import com.winchain.chainbill.basic.activity.vo.BasCusCpnVo;
import com.winchain.chainbill.util.ExcelGenUtil;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CusCpnController extends BaseController {
	@Autowired
	private BasCusCpnService basCusCpnService;

	@RequestMapping
	@Logging(module = "����������", methods = "������������������")
	public List<BasCusCpnVo> getListByPage(PageLimit limit, BasCusCpnVo basCusCpnVo) {
		return this.basCusCpnService.selectCusCpnsByPage(limit, basCusCpnVo);
	}

	@RequestMapping
	@Logging(module = "����������", methods = "������������������")
	public Map<String, Object> getStats(BasCusCpnVo basCusCpnVo) {
		return this.basCusCpnService.getStats(basCusCpnVo);
	}

	@RequestMapping
	@Logging(module = "����������", methods = "��������������")
	public BasCusCpnVo getDetail(String cusCpnId) {
		return this.basCusCpnService.getCusCpnDetail(cusCpnId);
	}

	@RequestMapping
	@ResponseBody
	@Logging(module = "����������", methods = "������������������")
	public void exportCusCpnList(BasCusCpnVo basCusCpnVo, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Map<String, Object> map = new HashMap();
		map.put("datas", this.basCusCpnService.selectCusCpns(basCusCpnVo));
		String execelTemp = "/template/excel/cusCpnList.xlsx";
		String fileName = "����������";

		map.put("listNm", fileName);
		InputStream is = ExcelGenUtil.getInstance().GenerateExcelForStream(execelTemp, map);
		CommonFileUtil.writeFileToClient(fileName + ".xlsx", is, response, request);
	}

	@RequestMapping
	@Logging(module = "����������", methods = "��������������")
	public List<BasCusCpnVo> getCusCpns(BasCusCpnVo basCusCpnVo) {
		if (StringUtil.emptyAndNull(basCusCpnVo.getCusId())) {
			basCusCpnVo.setCusId(CommonDataUtil.getCurEntId());
		}
		return this.basCusCpnService.selectCusCpns(basCusCpnVo);
	}
}